﻿define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Credit_repayment, $stateParams, GoPage, Auth, GoDialog) {
		
		$scope.store_id = $stateParams.id;
		
		$scope.$on('$ionicView.afterEnter', function(){
			var Infos = Auth.get_loginInfo();
			$scope.issue_type = Infos.issue_type;//1买家    2卖家
			$scope.init_data();
		},false)
		
		//初始化页面
		$scope.init_data = function() {
			var type = 0;
			if($scope.issue_type==1){
				type = 1;
			}
			Credit_repayment.agent_credit($scope.store_id,type,function(data){
//				console.log(data)
				if(!data.success){
					GoDialog.alert("提示",data.msg,function(){
						GoPage.go_back();
					});
					return;
				}
				$scope.data=data.result;				
			});
		}
		
		
		//立即还款
		$scope.onshow_payment=function(){
			GoPage.go_states("confirm_payment",{
				"id":$scope.store_id
			});	
		}
		
		//明细
		$scope.onshow_list = function(){
			GoPage.go_states("credit_repayment_list",{
				"store_id":$scope.store_id
			});	
		}
		
		
	}

	controller.$inject = ['$scope', 'Credit_repayment', '$stateParams', 'GoPage', 'Auth', 'GoDialog'];

	return app.registerController("credit_repaymentctrl", controller);
});